package com.ruoyi.safety.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //添加
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.safety.mapper.SafetyPointRealTimeMapper;
import com.ruoyi.safety.domain.SafetyPointRealTime;
import com.ruoyi.safety.service.ISafetyPointRealTimeService;

/**
 * 测点实时信息数据Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@Service
public class SafetyPointRealTimeServiceImpl extends ServiceImpl<SafetyPointRealTimeMapper, SafetyPointRealTime> implements ISafetyPointRealTimeService //修改
{
    @Autowired
    private SafetyPointRealTimeMapper safetyPointRealTimeMapper;

    /**
     * 查询测点实时信息数据
     *
     * @param pointCode 测点实时信息数据主键
     * @return 测点实时信息数据
     */
    @Override
    public SafetyPointRealTime selectSafetyPointRealTimeByPointCode(String pointCode) {
        return safetyPointRealTimeMapper.selectSafetyPointRealTimeByPointCode(pointCode);
    }

    /**
     * 查询测点实时信息数据列表
     *
     * @param safetyPointRealTime 测点实时信息数据
     * @return 测点实时信息数据
     */
    @Override
    public List<SafetyPointRealTime> selectSafetyPointRealTimeList(SafetyPointRealTime safetyPointRealTime) {
        List<SafetyPointRealTime> realTimeList = safetyPointRealTimeMapper.selectSafetyPointRealTimeList(safetyPointRealTime);
        List<SafetyPointRealTime> collect = realTimeList.stream().map(ObjInList -> {
            String pointValue = ObjInList.getPointValue();
            String sensorTypeName = ObjInList.getSensorTypeName();
            if (pointValue != null && !"".equals(pointValue)) {
                switch (sensorTypeName) {
                    case "局部通风机":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("停");
                        } else {
                            ObjInList.setPointValue("开");
                        }
                        break;
                    case "风门":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("风门关闭");
                        } else {
                            ObjInList.setPointValue("风门打开");
                        }
                        break;
                    case "风筒状态":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("风筒无风");
                        } else {
                            ObjInList.setPointValue("风筒有风");
                        }
                        break;
                    case "设备开停":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("停止");
                        } else {
                            ObjInList.setPointValue("开");
                        }
                        break;
                    case "开关":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("关");
                        } else {
                            ObjInList.setPointValue("开");
                        }
                        break;
                    case "风向":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("逆风");
                        } else {
                            ObjInList.setPointValue("顺风");
                        }
                        break;
                    case "煤仓空满":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("空仓");
                        } else {
                            ObjInList.setPointValue("满仓");
                        }
                        break;
                    case "烟雾":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("无烟雾");
                        } else {
                            ObjInList.setPointValue("有烟雾");
                        }
                        break;
                    case "断电器":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("断电");
                        } else {
                            ObjInList.setPointValue("复电");
                        }
                        break;
                    case "主通风机":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("停");
                        } else {
                            ObjInList.setPointValue("开");
                        }
                        break;
                    case "馈电器":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("负荷侧无电压");
                        } else {
                            ObjInList.setPointValue("负荷侧有电压");
                        }
                        break;
                    case "声光报警器":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("无报警");
                        } else {
                            ObjInList.setPointValue("报警");
                        }
                        break;
                    case "计量开停控制器":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("停止");
                        } else {
                            ObjInList.setPointValue("开启");
                        }
                        break;
                    case "控制量":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("断开");
                        } else {
                            ObjInList.setPointValue("合并");
                        }
                        break;
                    case "馈电":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("关");
                        } else {
                            ObjInList.setPointValue("开");
                        }
                        break;
                    case "分站":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("故障");
                        } else {
                            ObjInList.setPointValue("正常");
                        }
                        break;
                    case "电源状态":
                        if ("0".equals(pointValue)) {
                            ObjInList.setPointValue("无电");
                        } else if ("1".equals(pointValue)) {
                            ObjInList.setPointValue("交流供电");
                        } else if ("2".equals(pointValue)) {
                            ObjInList.setPointValue("直流供电");
                        }
                        break;
                    default:
                        break;
                }
            }
            return ObjInList;
        }).collect(Collectors.toList());


        return collect;
    }

    /**
     * 新增测点实时信息数据
     *
     * @param safetyPointRealTime 测点实时信息数据
     * @return 结果
     */
    @Override
    public int insertSafetyPointRealTime(SafetyPointRealTime safetyPointRealTime) {
        return safetyPointRealTimeMapper.insertSafetyPointRealTime(safetyPointRealTime);
    }

    /**
     * 修改测点实时信息数据
     *
     * @param safetyPointRealTime 测点实时信息数据
     * @return 结果
     */
    @Override
    public int updateSafetyPointRealTime(SafetyPointRealTime safetyPointRealTime) {
        return safetyPointRealTimeMapper.updateSafetyPointRealTime(safetyPointRealTime);
    }

    /**
     * 批量删除测点实时信息数据
     *
     * @param pointCodes 需要删除的测点实时信息数据主键
     * @return 结果
     */
    @Override
    public int deleteSafetyPointRealTimeByPointCodes(String[] pointCodes) {
        return safetyPointRealTimeMapper.deleteSafetyPointRealTimeByPointCodes(pointCodes);
    }

    /**
     * 删除测点实时信息数据信息
     *
     * @param pointCode 测点实时信息数据主键
     * @return 结果
     */
    @Override
    public int deleteSafetyPointRealTimeByPointCode(String pointCode) {
        return safetyPointRealTimeMapper.deleteSafetyPointRealTimeByPointCode(pointCode);
    }

    @Override
    public int getCountOver() {

        SafetyPointRealTime safetyPointRealTime = new SafetyPointRealTime();
        safetyPointRealTime.setSensorTypeName("环境瓦斯");
        List<SafetyPointRealTime> realTimeList = safetyPointRealTimeMapper.selectSafetyPointRealTimeList(safetyPointRealTime);
        int count = 0;
        for (SafetyPointRealTime pointRealTime : realTimeList) {
            if (Integer.parseInt(pointRealTime.getPointValue()) > 0.3){
                count ++ ;
            }
        }
        return count;
    }

    @Override
    public int getYyhtan() {
        SafetyPointRealTime safetyPointRealTime = new SafetyPointRealTime();
        safetyPointRealTime.setSensorTypeName("一氧化碳");
        List<SafetyPointRealTime> realTimeList = safetyPointRealTimeMapper.selectSafetyPointRealTimeList(safetyPointRealTime);
        int count = 0;
        for (SafetyPointRealTime pointRealTime : realTimeList) {
            if (Double.parseDouble(pointRealTime.getPointValue()) > 0){
                count ++ ;
            }
        }
        return count;
    }

    @Override
    public void insertRealTimeBatch(List<SafetyPointRealTime> pointInfoRealTimeArrayList) {
        safetyPointRealTimeMapper.insertRealTimeBatch(pointInfoRealTimeArrayList);
        return;
    }

    @Override
    public void updateDataBatch(List<SafetyPointRealTime> pointInfoRealTimeArrayList) {
        safetyPointRealTimeMapper.updateDataBatch(pointInfoRealTimeArrayList);
        return;
    }
}
